﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace ResourceLocalization.Converters
{

    [ContentProperty("Values")]
    public class KeyAlternationConverter : IValueConverter
    {
        private List<object> _values = new List<object>();
        public IList Values => _values;
        public object Convert(object o, Type targetType, object parameter, CultureInfo culture)
        {

            if (_values.Count > 0)
            {
                int num = (int)o % _values.Count;
                if (num < 0)
                {
                    num += _values.Count;
                }
                var resourceKey = _values[num].ToString().Trim();

                var value = WPFLocalizeExtension.Engine.LocalizeDictionary.Instance.GetLocalizedObject(resourceKey, null, null);
                if (value != null)
                {
                    return value;
                }
                else
                {
                    return resourceKey;
                }
            }
            return DependencyProperty.UnsetValue;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="o"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object o, Type targetType, object parameter, CultureInfo culture)
        {
            return DependencyProperty.UnsetValue;
        }
    }
}

